def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            return False
    return True

def giguga(number):
    number_str = str(number)
    if len(number_str) != 4 or not number_str.isdigit():
        return 0
    for length in range(4, 0, -1):
        for start in range(0, 5 - length):
            sub_num = int(number_str[start:start+length])
            if is_prime(sub_num):
                return sub_num
    return 0
number = int(input())
print(giguga(number))
